package main

func maxProfit(prices []int) int {
	ans := 0
	for i := 1; i < len(prices); i++ {
		if prices[i] > prices[i-1] {
			ans += prices[i] - prices[i-1]
		}
	}
	return ans
}

func maxProfit2(prices []int) int {
	dp0, dp1 := 0, -prices[0]
	for i := 1; i < len(prices); i++ {
		if dp1+prices[i] > dp0 {
			dp0 = dp1 + prices[i]
		}
		if dp0-prices[i] > dp1 {
			dp1 = dp0 - prices[i]
		}
	}
	return dp0
}
